<template>
  <div>
    <!-- 头部区域 -->
    <div class="page-header">
      <div class="title-section">
        <h1 class="page-title">提现记录</h1>
      </div>
    </div>
    <!-- 表格区域 -->
    <div class="margin-top">
      <el-table ref="multipleTableRef" :data="listData" style="width: 100%">
        <el-table-column type="selection" width="55" />

        <el-table-column property="order_on" label="提现单号"></el-table-column>

        <el-table-column property="user_name" label="用户" />
        <el-table-column property="address" label="地址" />

        <el-table-column property="agent_commission" label="类型">
          <template #default="scope">
            <div v-if="scope.row.pay_type == 0"> usdt</div>
            <div v-if="scope.row.pay_type == 1"> paypal</div>
          </template>
        </el-table-column>

        <el-table-column property="agent_commission" label="提现金额">
          <template #default="scope">
            <div> {{ scope.row.money || 0 }}</div>
          </template>
        </el-table-column>

        <el-table-column property="pay_money" label="支付金额">
          <template #default="scope">
            <div> {{ scope.row.pay_money || 0 }}</div>
          </template>
        </el-table-column>

        <el-table-column property="status" label="状态">
          <template #default="scope">
            <template v-for="item in statusData">
              <el-tag class="ml-2" :key="item.id" v-if="scope.row.status === item.value">
                {{ item.label }}
              </el-tag>
            </template>
          </template>
        </el-table-column>

        <el-table-column property="create_time" label="申请时间"> </el-table-column>
      </el-table>
    </div>

    <!-- 分页区域 -->
    <div class="margin-top">
      <Pagination :total="total" @change="changePage" />
    </div>

    <!-- 产品表单模态框 -->
    <ProductFormModal v-model:visible="productModalVisible" :productData="currentProduct" :isEdit="isEditMode"
      @submit="handleProductSubmit" />

    <!-- 添加价格弹窗 -->
    <ProductPriceFormModal ref="productPriceFormModalRef" @reload="searchTable" />
  </div>
</template>

<script lang="ts" setup>
import dayjs from 'dayjs'
import { ref, reactive, computed, toRef, onMounted, watch } from 'vue'
import Select from '@/components/admin/Select.vue'
import { useRoute } from 'vue-router'
import useTableHook from '@/hooks/useTableHook'
import { getRegionPayDataListApi } from '@/api/index'
import { RefreshRight } from '@element-plus/icons-vue'
import ProductFormModal from '@/components/admin/merchants/ProductFormModal.vue'
import ProductPriceFormModal from '@/components/admin/merchants/ProductPriceFormModal.vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import Pagination from '@/components/admin/Pagination.vue'

const statusData = [
  {
    label: '全部状态',
    value: ''
  },
  {
    label: '发起提款',
    value: 0,
    color: '#f4f4f5'
  },
  {
    label: '区域代理同意',
    value: 1,
    color: '#409eff'
  },
  {
    label: '等待最后确认',
    value: 4,
    color: '#e6a23c'
  },
  {
    label: '通过',
    value: 5,
    color: '#66c03a'
  },
  {
    label: '驳回',
    value: 6,
    color: '#909399'
  },
]
const payStatusData = [
  {
    label: '待付款',
    value: 0,
    color: ''
  },
  {
    label: '付款成功',
    value: 2,
    color: '#409eff'
  },
  {
    label: '取消付款',
    value: 3,
    color: '#e6a23c'
  },
]
const queryInfo = ref({
  order_no: '',
  dates: [],
  start_time: '',
  end_time: '',
  status: '',
  page: 1,
  limit: 10,
})

const searchFormRef = ref<FormInstance>()

// 重置表格
const resetTable = () => {
  searchFormRef.value.resetFields()

  queryInfo.value.start_time = ''

  queryInfo.value.end_time = ''

  searchTable()
}

const changeDate = (record) => {
  queryInfo.value.start_time = queryInfo.value.dates[0]
  queryInfo.value.end_time = queryInfo.value.dates[1]
  searchTable()
}

onMounted(() => {
  initTable()
})

const {
  total,
  listData,
  searchTable,
  initTable,
  changePage,
} = useTableHook(queryInfo.value, getRegionPayDataListApi)

defineExpose({
  searchTable
})
</script>

<style lang="scss" scoped>
/* 头部区域样式 */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 15px;
}

.title-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.page-title {
  font-size: 24px;
  font-weight: 600;
  margin: 0;
  color: #2c3e50;
}

.merchant-name {
  color: #e74c3c;
}

.back-link {
  display: inline-flex;
  align-items: center;
  font-size: 14px;
  color: #7f8c8d;
  text-decoration: none;
  transition: color 0.3s;
  margin-top: 5px;
}

.back-link:hover {
  color: #e74c3c;
}

.back-link i {
  margin-right: 5px;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.btn-primary {
  background-color: #e74c3c;
  color: white;
  border: none;
  padding: 10px 15px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  font-weight: 600;
  transition: background-color 0.3s;
}

.btn-primary:hover {
  background-color: #c0392b;
}

.btn-primary i {
  margin-right: 5px;
}
</style>
